using Gateway.IApplication.BaseInput;
using Gateway.IApplication.Language;
using Gateway.IApplication.Language.Input;
using Gateway.IQuery.Language;
using Gateway.IQuery.Language.Result;

namespace Gateway.UI.Api.Controllers;

/// <summary>
/// 运行语言服务
/// </summary>
public class LanguageController : BaseController
{
    private readonly ILanguageApp _app;
    private readonly ILanguageQuery _query;

    /// <summary>
    /// 
    /// </summary>
    /// <param name="app"></param>
    /// <param name="query"></param>
    public LanguageController(ILanguageApp app, ILanguageQuery query)
    {
        _app = app;
        _query = query;
    }

    /// <summary>
    /// 创建、更新
    /// </summary>
    /// <param name="input"></param>
    /// <returns>返回主键标识</returns>
    [HttpPost, Route("set")]
    public async Task<bool> Add(CreateLanguageInput input)
    {
        return await _app.Set(input);
    }

    /// <summary>
    /// 删除
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    [HttpPost, Route("remove")]
    public async Task<bool> Remove(RemoveInput input)
    {
        return await _app.Remove(input);
    }

    /// <summary>
    /// 禁用/启用
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    [HttpPost, Route("disable")]
    public async Task<bool> Disable(DisableInput input)
    {
        return await _app.Disable(input);
    }

    /// <summary>
    /// 运行语言列表
    /// </summary>
    /// <returns></returns>
    [HttpGet, Route("list/all")]
    public async Task<List<LanguageDetailResult>> GetAllList()
    {
        return await _query.GetAllList();
    }


    /// <summary>
    /// 获取可用的信息- 未删除  未禁用
    /// </summary>
    /// <returns></returns>
    [HttpGet, Route("list/available")]
    public async Task<List<LanguageSimpleResult>> GetAvailableList()
    {
        return await _query.GetAvailableList();
    }


    /// <summary>
    /// 创建、更新-扩展类库
    /// </summary>
    /// <param name="input"></param>
    /// <returns>返回主键标识</returns>
    [HttpPost, Route("set/code")]
    public async Task<bool> AddExtensionCode(LanguageExtensionCodeInput input)
    {
        return await _app.SetExtensionCode(input);
    }

    /// <summary>
    /// 删除-扩展类库
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    [HttpPost, Route("remove/code")]
    public async Task<bool> RemoveExtensionCode(RemoveInput input)
    {
        return await _app.RemoveCode(input);
    }

    /// <summary>
    /// 根据运行语言标识获取 扩展代码类库
    /// </summary>
    /// <param name="id"></param>
    /// <returns></returns>
    [HttpGet, Route("code/list/{id}")]
    public async Task<List<LanguageExtensionCodeDetailResult>> GetExtensionCodeList(string id)
    {
        return await _query.GetCodes(id);
    }

    /// <summary>
    /// 根据运行语言标识获取 扩展代码类库
    /// </summary>
    /// <param name="lang">语言code</param>
    /// <returns></returns>
    [HttpGet, Route("code/list/byLang")]
    public async Task<List<LanguageExtensionCodeDetailResult>> GetExtensionCodeListByLang(string lang)
    {
        return await _query.GetCodesByLang(lang);
    }
}